package org.wangzx.framework.security.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.web.savedrequest.SavedRequest;

import java.util.List;

/**
 * Created by WangZX on 2018/7/12.
 */
public class RequestUtil {
    public static boolean hasJsonHeader(SavedRequest savedRequest){
        if (savedRequest == null){
            return false;
        }
        List<String> headerValues = savedRequest.getHeaderValues("content-type");
        for (String headerValue:headerValues) {
            if (StringUtils.equals(headerValue,"application/json")){
                return true;
            }
        }
        return false;
    }
    public static boolean hasHtmlHeader(SavedRequest savedRequest){
        if (savedRequest == null){
            return false;
        }
        List<String> headerValues = savedRequest.getHeaderValues("content-type");
        for (String headerValue:headerValues) {
            if (StringUtils.equals(headerValue,"text/html")){
                return true;
            }
        }
        return false;
    }
}
